package com.yztc.youbadbad.ui.homepage;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.yztc.youbadbad.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 助养
 *
 * */
public class ZhuyangHomeFragment extends Fragment {


    @BindView(R.id.webview_zhuyang)
    WebView webviewZhuyang;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_zhuyang_home, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        webviewZhuyang.setWebViewClient(new WebViewClient());
        // 让webView支持javascript语句。但是类似alert()这样的特殊语句依然不支持
        webviewZhuyang.getSettings().setJavaScriptEnabled(true);
        // 为了让webview支持类似alert()这样的特殊语句，必须设置以下
        webviewZhuyang.setWebChromeClient(new WebChromeClient());

        webviewZhuyang.loadUrl("http://sale.baobeigezi.com/2016/6/8_1/android/index.html");
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        webviewZhuyang.stopLoading(); //停止加载
        ((ViewGroup)webviewZhuyang.getParent()).removeView(webviewZhuyang); //把webview从视图中移除
        webviewZhuyang.removeAllViews(); //移除webview上子view
        webviewZhuyang.clearCache(true); //清除缓存
        webviewZhuyang.clearHistory(); //清除历史
        webviewZhuyang.destroy(); //销毁webview自身
    }
}
